<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script>
	$(function(){
		$("#fileDelete0").click(function(){
			 if($("#fileUpload0").html()==""){
				 alert("등록된 파일이 없습니다.");
			 }else{
				 if(confirm("파일을 삭제하시겠습니까?")){
					 $.ajax({
						 type:"get",
						 url:"auth_deletePublicBoardFile.do",
						 data:"newfilename="+$(this).parent().parent().find(".newfilename").val()+"&fileNo="+$(this).parent().parent().find(".fileNo").val(),
						 dataType:"json",
						 success:function(){
							 str="<input type='file' name='files[0]'>";
							 $("#fileUpload0").html(str);			 
						 }//callback
					 });//ajax
				 }//confirm
			 }//if
		 });
		$("#fileDelete1").click(function(){
			 if($("#fileUpload1").html()==""){
				 alert("등록된 파일이 없습니다.");
			 }else{
				 if(confirm("파일을 삭제하시겠습니까?")){
					 $.ajax({
						 type:"get",
						 url:"auth_deletePublicBoardFile.do",
						 data:"newfilename="+$(this).parent().parent().find(".newfilename").val()+"&fileNo="+$(this).parent().parent().find(".fileNo").val(),
						 dataType:"json",
						 success:function(){
							 str="<input type='file' name='files[1]'>";
							 $("#fileUpload1").html(str);			 
						 }//callback
					 });//ajax
				 }//confirm
			 }//if
		 });
		$("#fileDelete2").click(function(){
			 if($("#fileUpload2").html()==""){
				 alert("등록된 파일이 없습니다.");
			 }else{
				 if(confirm("파일을 삭제하시겠습니까?")){
					 $.ajax({
						 type:"get",
						 url:"auth_deletePublicBoardFile.do",
						 data:"newfilename="+$(this).parent().parent().find(".newfilename").val()+"&fileNo="+$(this).parent().parent().find(".fileNo").val(),
						 dataType:"json",
						 success:function(){
							 str="<input type='file' name='files[2]'>";
							 $("#fileUpload2").html(str);			 
						 }//callback
					 });//ajax
				 }//confirm
			 }//if
		 });
		 $("#updateF").submit(function(){
				if($("#title").val()==""){
					alert("제목을 입력하세요");
					return false;
				}else if($("#content").val()==""){
					alert("내용을 입력하세요");
					return false;
				}
			});//submit
		//취소버튼 눌렀을때 confirm창이 뜬다.
			$("#cancel").click(function(){
				if(confirm("글수정을 취소하시겠습니까?")){
					location.href="${initParam.root}public/auth_detailBoardNoHit.do?no=${requestScope.bvo.no}"; 
				}
			}) ;
	});//ready
</script>
<form action="${initParam.root }public/auth_updatePublicBoard.do"
	method="post" enctype="multipart/form-data" id="updateF">
	<input type="hidden" name="no" value="${requestScope.bvo.no}">
		<table width="550">
			<tr>
				<td align="right">Title</td>
				<td><input type="text" size="65" name="title" value="${requestScope.bvo.title }" id="title"></td>
			</tr>
			<tr>
				<td align="right" valign="top">
					Content
				</td>
				<td>
					<textarea rows="15" cols="57" name="content" id="content" style="resize: none;">${requestScope.bvo.content }</textarea>
				</td>
			</tr>
			<tr>
				<td rowspan="6" align="right" valign="top">File<br>Attachment</td>
			</tr>
			
			<c:forEach items="${requestScope.list}" varStatus="i" var="list">
				<tr>
					<td colspan="2" align="left"><input type="button" name="fileDelete" value="파일삭제"
						id="fileDelete${i.index}">${list.PUB_ORGFILENAME} <input
						type="hidden" class="newfilename" value="${list.PUB_NEWFILENAME}">
						<input type="hidden" class="fileNo" value="${list.PUB_FILE_NO}">
					</td>
				<tr>
			</c:forEach>
			<c:forEach begin="1" end="${3-requestScope.listLength}" varStatus="i">
				<tr>
					<td colspan="2" align="left"><input type="button" name="fileDelete" value="파일삭제"
						id="fileDelete${2-i.end+i.index}">
						<input type="file"
						name="files[${2-i.end+i.index}]"></td>
				<tr>
			</c:forEach>
			
			<tr>
				<td colspan="2" align="right" style="padding-right: 25px;">
					<input type="button" name="cancel" id="cancel" value="취소">
					<input type="submit" value="확인">
				</td>
			</tr>
		</table>
	</form>







